/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chelydra.sharelydra.client.message;

/**
 *
 * @author Benjamin
 */
public class DownloadPart extends Message{

    private int fileId;
    private int startByte;
    private int finishByte;

    public DownloadPart(){
        super(3,"");
    }

    public DownloadPart(int fileId,int startByte, int finishByte){
        super(3,Integer.toString(fileId)+"-"+Integer.toString(startByte)
                +"-"+Integer.toString(finishByte));
        this.fileId=fileId;
        this.startByte=startByte;
        this.finishByte=finishByte;
        
    }
    
    
    public int getFileId() {
        return fileId;
    }

    public void setFileId(int fileId) {
        this.fileId = fileId;
    }

    public int getFinishByte() {
        return finishByte;
    }

    public void setFinishByte(int finishByte) {
        this.finishByte = finishByte;
    }

    public int getStartByte() {
        return startByte;
    }

    public void setStartByte(int startByte) {
        this.startByte = startByte;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }
    
    

    @Override
    public String toString(){
        this.data = Integer.toString(this.fileId)+"-"+Integer.toString(this.startByte)
                +"-"+Integer.toString(this.finishByte);
        return super.toString();
    }

    @Override
    public void fromString(String str){
        super.fromString(str);
        int firstMinusPos=this.data.indexOf("-");
        int SecondMinusPos=this.data.indexOf("-",firstMinusPos+1);
        this.fileId=Integer.parseInt(this.data.substring(0,firstMinusPos));
        this.startByte=Integer.parseInt(this.data.substring(firstMinusPos+1,SecondMinusPos));
        this.finishByte=Integer.parseInt(this.data.substring(SecondMinusPos+1));
    }

}
